package com.shangxia.monomer.study.thread.base.queue;

import lombok.extern.slf4j.Slf4j;


import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;

/**
 * @ProjectName: monomer
 * @ClassName: BlockingDequeDemo
 * @Time: 2021/10/2
 * @Author: zhouy
 * @Description:
 * @Experience:
 */

@Slf4j
public class BlockingDequeDemo {
    public static void main(String[] args) {
        BlockingQueue queue = new ArrayBlockingQueue(3);

        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                try {
                    queue.put(i);
                    System.out.println(i + " put");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();


        for (int i = 0; i < 10; i++) {
            try {
                System.out.println(queue.take() + " poll");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("over");
    }
}
